package com.example.translateappjava.Service.AliyunAPI;
import com.baidu.aip.util.Base64Util;
import com.baidu.aip.util.*;
import com.baidu.aip.client.BaseClient;
import com.baidu.aip.imageclassify.AipImageClassify;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;

public class AliyunAPIImplication implements AliyunAPIInterface.ImageUrl{
    public static final String APP_ID = "72804373";
    public static final String API_KEY = "YX4hg3H5HMtrroTI85hEX5Xh";
    public static final String SECRET_KEY = "nKBryIlt577SWbBOF0XOROmyCG1CT5D0";




    @Override
    public String getFilePathRecognizeResult(byte[] file) throws Exception {
        AipImageClassify client = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("top_num", "3");
        options.put("filter_threshold", "0.7");
        options.put("baike_num", "5");
        JSONObject res = client.dishDetect(file, options);
//        System.out.println(res.toString(2));

        return res.toString(2);
    }
}
